/*
 *  @ProductName@
 *  Copyright (C) @CopyrightYear@
 *    National Institute of Advanced Industrial Science and Technology (AIST)
 *    Registration Number: @AISTRegistrationNumber@
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package jp.go.aist.six.vuln.core.scap.nvd;

import jp.go.aist.six.util.castor.CastorDao;
import jp.go.aist.six.vuln.model.scap.nvd.Nvd;
import jp.go.aist.six.vuln.model.scap.vulnerability.Vulnerability;
import java.util.Collection;
import java.util.UUID;



/**
 * @author  Akihito Nakamura, AIST
 * @version $Id: NvdDao.java 256 2010-06-14 03:58:05Z nakamura5akihito $
 */
public class NvdDao
    extends CastorDao<Nvd>
{

//    /**
//     * Logger.
//     */
//    private static Log  _LOG = LogFactory.getLog( NvdDao.class );



    /**
     * Constructor.
     */
    public NvdDao()
    {
        super( Nvd.class );
    }



    //**************************************************************
    //  Dao, CastorDao
    //**************************************************************

    @Override
    public Object create(
                    final Nvd nvd
                    )
    {
        if (nvd.getPersistentID() == null) {
            String  uuid = UUID.randomUUID().toString();
            nvd.setPersistentID( uuid );
        }

        Collection<Vulnerability>  entry_list = nvd.getEntry();
        if (entry_list != null  &&  entry_list.size() > 0) {
            for (Vulnerability  entry : entry_list) {
                NvdVulnerabilityAssociation  assoc = new NvdVulnerabilityAssociation( nvd, entry );
                getForwardingDao( NvdVulnerabilityAssociation.class ).sync( assoc );
            }

//            Collection<Vulnerability>  p_entry_list = new ArrayList<Vulnerability>();
//            for (Vulnerability  entry : entry_list) {
//                Vulnerability  p_entry = getForwardingDao( Vulnerability.class ).sync( entry );
//                p_entry_list.add( p_entry );
//
//                NvdVulnerabilityAssociation  assoc = new NvdVulnerabilityAssociation( nvd, p_entry );
//                getForwardingDao( NvdVulnerabilityAssociation.class ).sync( assoc );
//            }
//
//            nvd.setEntry( p_entry_list );
        }


        return super.create( nvd );
    }

}
// NvdDao
